/**Class Matrix For basic manipulation on matrix 
*
*
* 
* @Author : Vishwajeet Dusane 
*/

#include<stdio.h>
#include<math.h>
#include<fstream.h>
#include<iostream.h>
class Matrix
{
   public:
  double matrix[100][100]; 
  int row,column;
  
   // Constructor
   Matrix();
   
   // Constructor
   //matrix of size n rows 
   Matrix(int);
   
   // Constructor
   //  matrix of size n (rows) * m (column) 
   Matrix(int,int);
   
   // Destructor
   ~Matrix();
   
  
  //read Matrix from file
  int readMatrix(char [50]);
  
  
  //use default matrix
  
   void useDefault();
   
  //swap Rows 
  void swapRow(int ,int) ; 
   
  //get elements from keyboard
  void newElement();  
   
   
  
  //returns TRUE if the augmented matrix is Transformed matrix
 //**************** int  isTransformed();  
  
  // swap rows, 
           
 
 // print Matrix   
   void printMatrix();
   
   
  //return particular element from the matrix for given row and column 
  //********8double getElement(int,int);
  
 /* 
  //  make entries 0 where i>j 
  //    U11 U12 U13
  //    0   U22 U23
  //    0    0  U33 
  void setUpperTriangular();  
  
  
  //  make entries 0 where i>j 
  
  void setLowerTriangular();  
  
  */
  
  
  //check whether given matrix is upper triangular or not ,return true
 //************ int  isUpperTriangular(); 
  
  //return true 1 if matrix is lower triangular 
//**************8  int  isLowerTriangular(); 
  
  
   
  //**********double operator^(double); //return's 
  };
  

  //---------------------------------------------------------------------------------------------  
 /* Matrix::Matrix(int row)
  {
    
    this.row=row;
    this.column =1;
    
    double **matrix = new double[row][1];
  
    
  }*/
  
 //---------------------------------------------------------------------------------------------- 
  Matrix::Matrix(int rowNumber,int columnNumber)
  {
     
    row=rowNumber;
    column =columnNumber;
  
      //double **matrix = new double[rowNumber][columnNumber];
      
      
      
  
  }
  
  //----------------------------------------------------------------------------------------------
  Matrix::Matrix()
  {
  
    row=3;
    column=3;     
   
  }
  
  
  //---------------------------------------------------------------------------------------------------
  Matrix::~Matrix()
  {
  
     //delete **matrix;
   
  }
 
   
 //----------------------------------------------------------------------------------------------------
 
 int Matrix::readMatrix(char fname[50])
  {
    
    ifstream fin(fname);
     
     if(!fin)
     {
       cout<<"ERROR : While Opening File "<<fname<<endl;
       return 0;
     
     }
     
     
     fin>>row;
     fin>>column; 
     
     for(int i=0; i<row ;i++)
     {
       for(int j=0;j<column;j++)
        {
            //fin.read((double) &matrix[i][j],sizeof(double));
	    fin>>matrix[i][j];
	} 
     }
    fin.close();
    return 1; 
  }

   //----------------------------------------------------------------------------------------------------
  
  void Matrix::printMatrix()
  {
  
     for(int i=0; i<row ;i++)
     {
       for(int j=0;j<column;j++)
        {
            cout<<"  "<<matrix[i][j];
	} 
	cout<<endl;
     }
 
  }
  
  
 //---------------------------------------------------------------------------------------------------
  
  void Matrix::useDefault()
  {
   
   row=3;
   column=3;
   
   matrix[0][0]=5;    matrix[0][1]=2;	matrix[0][2]=1;//	matrixA[0][3]=7;
   matrix[1][0]=1;     matrix[1][1]=3;	matrix[1][2]=-1;//	matrixA[1][3]=5;
   matrix[2][0]=2;     matrix[2][1]=1;	matrix[2][2]=4;//	matrixA[2][3]=9;
  // matrixA[3][0]=7;     matrixA[3][1]=5;	matrixA[3][2]=9;	matrixA[3][3]=10;
   printMatrix();   
  
  } 
  
  
  
//---------------------------------------------------------------------------------------------------
 void Matrix::newElement()
 {
      cout<<"Enter New Element";
     
     for(int i=0; i<row ;i++)
     {
       for(int j=0;j<column;j++)
        {
            cin>>matrix[i][j];
	} 
	cout<<endl;
     }
   
       cout<<"Element stored ";
   
 
 }
 
 void Matrix::swapRow(int currRow,int nextRow)
 {
  double temp;
  
       for(int j=0;j<column;j++)
        {
          temp=matrix[currRow][j];
	  matrix[currRow][j]=matrix[nextRow][j];
	  matrix[nextRow][j]=temp;
	
	} 
	
     
   
  
 
 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  
  
  
  
